Skip to main content
Version: Next

FE Code Quality, Formatting, and Linting Documentation

1. Introduction

This document provides guidelines for maintaining code quality, consistent formatting, and linting standards in native iOS (Swift) and Android (Kotlin) applications. It covers the setup and usage of SwiftLint for iOS and Ktlint for Android, including customizing lint rules to remove unwanted lints.

2. SwiftLint Setup and Usage (iOS)

2.1. Installation

  1. Install SwiftLint:

    • Using Homebrew (macOS):
      brew install swiftlint
    • Using CocoaPods (Optional): Add to your Podfile:
      target 'YourAppTarget' do
      pod 'SwiftLint'
      end
      Run pod install.
  2. Configuration:

    • Create a .swiftlint.yml file in the root of your Xcode project for custom rules and configurations. For example:
      disabled_rules:
      - colon
      - force_cast
      included:
      - Sources
      excluded:
      - Carthage

2.2. Integration with Xcode

  1. Run SwiftLint on Build:
    • Add a new "Run Script Phase" in your Xcode project settings:
      if which swiftlint >/dev/null; then
      swiftlint
      else
      echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
      fi

2.3. Usage

  • Command Line: Run SwiftLint from terminal in your project directory:

    swiftlint

  • Xcode Integration: Errors and warnings will appear in the Xcode Issue Navigator during builds.

3. Ktlint Usage (Android)

  • Command Line: Run Ktlint from terminal in your Android project directory:

    ./gradlew moduleName:ktlintLintFormat

or run it from the gradle tasks, its easier.

  • Whenever you are committing a branch, make sure you do the KTLint format as well before publishing the PR

4. Best Practices

  • Consistency: Follow established code style guidelines and enforce them uniformly across the project.
  • Custom Rules: Define and enforce project-specific linting rules and configurations.
  • Continuous Integration: Integrate SwiftLint and Ktlint checks in your CI/CD pipelines.
  • Documentation: Maintain and update .swiftlint.yml and build.gradle with project-specific rules and configurations.

5. Conclusion

By implementing SwiftLint for iOS and Ktlint for Android, developers can ensure consistent code quality, formatting, and adherence to coding standards. Customizing lint rules allows teams to remove unwanted lints and enforce specific project requirements, contributing to a more maintainable and efficient codebase.